﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.CRM.Component.Common;
using TRPOP.CRM.Component.Business;
using TRPOP.CRM.Component.Model;
using TRPOP.Common;

namespace TRPOP.CRM.Web
{
    /// <summary>
    /// 修改个人密码
    /// </summary>
    public partial class PersonalInfo_save : BaseAdmin
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadBase();
            }
        }

        /// <summary>
        /// 加载基本的数据
        /// </summary>
        void LoadBase()
        {
            EmployeeInfo oEmployeeInfo = base.GetCurrentEmployeeInfo();

            txtEmployeeName.Text = oEmployeeInfo.nvcEmployeeName;
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            EmployeeInfo oEmployeeInfo = base.GetCurrentEmployeeInfo();

            if (txtPassword.Text.Trim().MD5Normal() != oEmployeeInfo.nvcLoginPassword.ToString())
            {
                txtPassword.Text = string.Empty;

                AlertDialog("原密码错误，请重新输入原密码");
            }

            if (TextBox2.Text != txtPassword2.Text)
            {
                txtPassword2.Text = string.Empty;
                TextBox2.Text = string.Empty;

                AlertDialog("两次输入密码不一致，请重新输入新密码");
            }
            else if (EmployeeManage.SavePasword(oEmployeeInfo, txtPassword2.Text))
            {
                Alert("密码修改成功");
            }
        }
    }
}